package com.amentretenimiento;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class SystemService extends Service{
	Double lat,lon;
	LocationManager locationManager;

    LocationListener locationListenerGps = new LocationListener() {
        public void onLocationChanged(Location location) {
			lat = location.getLatitude();
			lon = location.getLongitude();
//			Log.i("LATITUD", ""+lat);
//			Log.i("LONGITUD", ""+lon);
        }
        public void onProviderDisabled(String provider) {}
        public void onProviderEnabled(String provider) {}
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    };
	
	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		_startService();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		_shutdownService();
	}
	
	private void _startService() {
				locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
				locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
		
	}
	
	private void _shutdownService() {
		locationManager.removeUpdates(locationListenerGps);

	}

}
